﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;
namespace DAO
{
    public class TheLoaiDAO
    {
        public DataTable LayTable()
        {
            String sql = "SELECT * from TheLoai ";
            SqlConnection con = DataProvider.ConnectDB();
            con.Open();
            SqlCommand command = new SqlCommand(sql, con);

            SqlDataAdapter adapter = new SqlDataAdapter(command);

            DataTable dt = new DataTable();
            adapter.Fill(dt);

            con.Close();
            return dt;
        }
        public void them(TheLoaiDTO tl)
        {
            String sql = "Insert into TheLoai(TenTheLoai) values(N'" +tl.TenTL+ "')";
            SqlConnection con = DataProvider.ConnectDB();
            con.Open();
            SqlCommand command = new SqlCommand(sql, con);
            int res = -1;
            res = command.ExecuteNonQuery();
            con.Close();
        }

        public void sua(TheLoaiDTO tl)
        {
            String sql = "UPDATE TheLoai SET TenTheLoai=N'" + tl.TenTL + "' where MaTheLoai =" + tl.MaTL;
            SqlConnection con = DataProvider.ConnectDB();
            con.Open();
            SqlCommand command = new SqlCommand(sql, con);
            int res = -1;
            res = command.ExecuteNonQuery();
            con.Close();
        }
        public void xoa(TheLoaiDTO tl)
        {
            String sql = "delete TheLoai where MaTheLoai =" + tl.MaTL;
            SqlConnection con = DataProvider.ConnectDB();
            SqlCommand command = new SqlCommand(sql, con);
            con.Open();
            int res = -1;
            res = command.ExecuteNonQuery();
            con.Close();
        }
    }
}
